package com.bdqn.mzc.config;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.CharacterEncodingFilter;

@Configuration
public class SystemFilterConfig {
    @Bean
    FilterRegistrationBean filterRegistrationBean() {
        //创建字符编码过滤器
        CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
        //设置强制使用指定编码
        characterEncodingFilter.setForceEncoding(true);
        //设置指定编码格式utf-8
        characterEncodingFilter.setEncoding("UTF-8");
        FilterRegistrationBean registrationBean = new FilterRegistrationBean();
        //设置字符编码过滤去
        registrationBean.setFilter(characterEncodingFilter);
        //设置字符编码过滤器路径
        registrationBean.addUrlPatterns("/*");
        return  registrationBean;
    }
}
